package com.xiaode.controller.app.mbit;

import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.ext.cors.EnableCORS;
import com.jfinal.kit.Ret;
import com.xiaode.common.anotation.JSONArrayString;
import com.xiaode.util.apidoc.annotation.Api;
import com.xiaode.util.apidoc.annotation.ApiOper;
import com.xiaode.util.apidoc.annotation.ApiPara;

import javax.validation.constraints.Size;

/**
 * mbti人格测试
 */
@Path("/mbti")
@Api("学生登录相关服务")
@EnableCORS
public class MbtiController extends Controller {
    @Inject
    MbtiService service;

    @ApiOper("查询题目数量")
    public void findQuestionNum()throws Exception{
        Ret ret = service.findQuestionNum();
        renderJson(ret);
    }


    @ApiOper("查询人格类型")
    public void findMbtiPersonality(
    		@ApiPara(value = "type",notes = "类型")String type,
            @ApiPara(value = "name",notes = "名称")String name)throws Exception{
        Ret ret = service.findMbtiPersonality(type,name);
        renderJson(ret);
    }

    @ApiOper("查询我的进度")
    public void findProgress()throws Exception{
    	Integer userId = getAttr("userId");
    	Integer userType = getAttr("userType");
        Ret ret = service.findProgress(userId, userType);
        renderJson(ret);
    }

    @ApiOper("保存我的进度")
    public void saveProgress(@JSONArrayString @ApiPara(value = "progress",notes = "答题进度[{id:xxx,choice:xxx}]")String progress)throws Exception{
    	Integer userId = getAttr("userId");
    	Integer userType = getAttr("userType");
        Ret ret = service.saveProgress(userId,userType,progress);
        renderJson(ret);
    }

    @ApiOper("查询题目")
    public void findQuestion(@ApiPara(value = "type",notes = "类型")Integer type)throws Exception{
        Ret ret = service.findQuestion(type);
        renderJson(ret);
    }

    @ApiOper("查询评论")
    public void findMbtiComments(@Size @ApiPara(value = "page",notes = "当前页")Integer page,
                                 @Size @ApiPara(value = "limit",notes = "每页大小")Integer limit)throws Exception{
        Ret ret = service.findMbtiComments(page,limit);
        renderJson(ret);
    }

    @ApiOper("发表评论")
    public void mbtiComment(@Size @ApiPara(value = "content",notes = "评论")String content)throws Exception{
    	Integer userId = getAttr("userId");
    	Integer userType = getAttr("userType");
        Ret ret = service.mbtiComment(userId, userType,content);
        renderJson(ret);
    }

    @ApiOper("删除我的评论")
    public void delMbtiComment(@Size @ApiPara(value ="commentId",notes = "评论id")Integer commentId)throws Exception{
    	Integer userId = getAttr("userId");
    	Integer userType = getAttr("userType");
        Ret ret = service.delMbtiComment(userId, userType,commentId);
        renderJson(ret);
    }



}
